home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_058 / newzap / sources / windows.c < prev   
C/C++ Source or Header  |  1992-05-06  |  5KB  |  164 lines

  1. /* WINDOWS.C - Support routines for NEWZAP.C - (c) 1986 John Hodgson */
  2.  
  3. #include "iff.h"
  4.  
  5. #define ERROR 1  /* error return code */
  6. #define KICKSTART_REV 33 /* minimum 1.2 rev for special funcs */
  7.  
  8. extern struct ExecBase *SysBase;
  9.  
  10. extern struct Gadget gadget[];
  11. extern char ScreenDump[],BrushDump[],SearchDump[];
  12. extern UBYTE title[],bakbuf[];  /* shared by all string gadgets */
  13. extern void *IntuitionBase,Search1();
  14. extern FreeBitMap();
  15.  
  16. struct PicMap pbitmap,arbitmap,brbitmap;
  17. struct Requester arequest,brequest;
  18. struct Window *pwindow,*OpenWindow();
  19.  
  20. UBYTE searchbuf[50]; /* string gadget input buffers */
  21.  
  22. OpenBackDrop()
  23. {
  24.   struct NewWindow NewWindow;
  25.  
  26.   setmem(&NewWindow,sizeof(NewWindow),0); /* pre-init to all zeroes */
  27.   
  28.   NewWindow.Width=640; NewWindow.Height=200;
  29.   NewWindow.DetailPen=NewWindow.BlockPen=-1;
  30.   NewWindow.IDCMPFlags=
  31.       CLOSEWINDOW|MENUPICK|MOUSEMOVE|RAWKEY|GADGETDOWN|GADGETUP;
  32.   NewWindow.Flags=WINDOWDEPTH|WINDOWCLOSE|WINDOWDRAG|SUPER_BITMAP|ACTIVATE;
  33.   NewWindow.FirstGadget=&gadget[0];
  34.   NewWindow.Title=&title[0];
  35.   NewWindow.BitMap=&pbitmap.BitMap;
  36.   NewWindow.Type=WBENCHSCREEN;
  37.  
  38.   if (ReadILBM(&ScreenDump[0],1,&pbitmap)) return(ERROR);
  39.   
  40.   if ((pwindow=OpenWindow(&NewWindow))==0L) {
  41.      FreeBitMap(&pbitmap.BitMap); return(ERROR); }
  42.  
  43.   return(0);
  44. }
  45.  
  46. CloseBackDrop()
  47. {
  48.   short i;
  49.  
  50.   CloseWindow(pwindow);
  51.  
  52.   /* Note that we free raster AFTER closing window! Important! */
  53.   FreeBitMap(&pbitmap.BitMap);
  54. }
  55.    
  56. InitHelpRequester()
  57. {
  58.   static struct Gadget argadget = {
  59.      0L,340,97,75,9,GADGHNONE,ENDGADGET,BOOLGADGET|REQGADGET,
  60.          0L,0L,0L,0L,0L,0L,0L };
  61.  
  62.   setmem(&arequest,sizeof(arequest),0); /* start w/fresh structure */
  63.  
  64.   arequest.LeftEdge=97; arequest.TopEdge=32;
  65.   arequest.Width=447;  arequest.Height=113;
  66.   arequest.ReqGadget=&argadget;
  67.   arequest.Flags=PREDRAWN;
  68.   arequest.ImageBMap=&arbitmap.BitMap;
  69.  
  70.   if (ReadILBM(&BrushDump[0],1,&arbitmap)) return(ERROR);
  71.  
  72.   return(0);
  73. }
  74.  
  75. FreeRequester()
  76. {
  77.   FreeBitMap(&arbitmap.BitMap);
  78. }
  79.    
  80. InitSearchRequester()
  81. {
  82.   static struct StringInfo searchinfo = {
  83.     &searchbuf[0],&bakbuf[0],0,30,0,0,0,0,71,53,0L,0L,0L };
  84.  
  85.   static struct Gadget brgadget[2] = { /* adjust if real requester! */
  86.     { &brgadget[1],344,6,40,12,GADGHNONE,RELVERIFY,BOOLGADGET,
  87.         0L,0L,0L,0L,0L,0L,0L },
  88.     { 0L,71,53,244,9,   /* search string gadget */
  89.         GADGHCOMP,RELVERIFY,
  90.            STRGADGET|REQGADGET,0L,0L,0L,0L,(APTR)&searchinfo,12,(APTR)&Search1 }
  91.   };
  92.  
  93.   setmem(&brequest,sizeof(brequest),0); /* start w/fresh structure */
  94.  
  95.   brequest.LeftEdge=123; brequest.TopEdge=38;
  96.   brequest.Width=400;  brequest.Height=101;
  97.   brequest.ReqGadget=&brgadget[0];
  98.   brequest.Flags=PREDRAWN;
  99.   brequest.ImageBMap=&brbitmap.BitMap;
  100.  
  101.   if (ReadILBM(&SearchDump[0],1,&brbitmap)) return(ERROR);
  102.  
  103.   return(0);
  104. }
  105.  
  106. FreeSearchRequester() /* provided for consistency */
  107. {
  108.   FreeBitMap(&brbitmap.BitMap);
  109. }
  110.  
  111. FakeRequest()
  112. {
  113.   /* I just can't get string gadgets in PREDRAWN requesters to work correctly
  114.      under 1.2. For now, we'll fake it with a borderless window. */
  115.  
  116.   struct NewWindow NewWindow;
  117.   struct Window *window;
  118.   struct IntuiMessage *reqmsg;
  119.   static struct IntuiMessage relaymsg; /* static 'cuz referenced outside! */
  120.   struct Gadget *gadgetptr;
  121.   
  122.   setmem(&NewWindow,sizeof(NewWindow),0); /* pre-init to all zeroes */
  123.  
  124.   NewWindow.LeftEdge=brequest.LeftEdge; NewWindow.TopEdge=brequest.TopEdge;
  125.   NewWindow.Width=brequest.Width; NewWindow.Height=brequest.Height;
  126.   NewWindow.IDCMPFlags=GADGETUP;
  127.   NewWindow.Flags=BORDERLESS|SUPER_BITMAP|ACTIVATE;
  128.   NewWindow.FirstGadget=brequest.ReqGadget;
  129.   NewWindow.BitMap=brequest.ImageBMap;
  130.   NewWindow.Type=WBENCHSCREEN;
  131.  
  132.   /* forget requester if lack of memory prevents window opening */
  133.   if ((window=OpenWindow(&NewWindow))==0L) return(ERROR);
  134.  
  135.   /* note : although this routine is meant to be a general-purpose
  136.      requester emulator, it's just too handy to activate the Search
  137.      menu's string requester (1.2 or later). We check the LibNode
  138.      because SoftVer in ExecBase is 0 (??) at the time of this writing. */
  139.  
  140.   if (SysBase->LibNode.lib_Version>=KICKSTART_REV)
  141.     ActivateGadget(&brequest.ReqGadget[1],window,0L);
  142.  
  143.   WaitPort(window->UserPort); /* wait for gadgetup */
  144.   reqmsg=(struct IntuiMessage *)GetMsg(window->UserPort); /* & dequeue msg */
  145.  
  146.   gadgetptr=(struct Gadget *)reqmsg->IAddress; /* fetch gadget pick */
  147.  
  148.   /* Assume : 1) all gadgets have the ENDGADGET flag set, and :
  149.               2) we don't want to broadcast about gadgets w/no ID!
  150.  
  151.      Msgs we care about get pipelined over to the main window, where
  152.      the newzap body should take care of replying to Intuition for us! */
  153.  
  154.   if (gadgetptr->GadgetID) {
  155.     relaymsg=*reqmsg; /* duplicate message */
  156.     relaymsg.ExecMessage.mn_ReplyPort=0; /* forget about replies */
  157.     PutMsg(pwindow->UserPort,&relaymsg); /* attach to main window! */
  158.   }
  159.   ReplyMsg(reqmsg); /* always reply to messages */
  160.  
  161.   CloseWindow(window); return(0); /* cleanup & leave */
  162. }
  163.   
  164.